import java.awt.Color;
import java.awt.Graphics;
import java.util.Map;

import com.speljohan.rsbot.bot.Bot;
import com.speljohan.rsbot.event.listeners.PaintListener;
import com.speljohan.rsbot.script.Script;

public class MouchiccDPBuilder extends Script implements PaintListener {

	private final long startTime = System.currentTimeMillis();
	public int TID = 0000;
	public int[] RuneIDs = { 563, 557, 556 };
	public String WhereToTele;

	public double getVersion() {
		return 1.0;
	}

	public String getAuthor() {
		return "Mouchicc";
	}

	public String getName() {
		return "DPBuilder";
	}

	public String getScriptCategory() {
		return "MouchiccScripts";
	}

	@Override
	public String getScriptDescription() {
		String html = "";
		html += "<html>";
		html += "<head>";
		html += "<style type=\"text/css\"> hr {color: white} p {margin-left: 20px}</style>";
		html += "</head>";
		html += "<body>";
		html += "<center>";
		html += "<b><font size=\"6\" color=\"red\">" + getName() + " v"
				+ getVersion() + " M" + "</font></b><br>";
		html += "<font size=\"3\" color=\"red\">Please start Anywhere.<br></font>";
		html += "<font size=\"4\" color=\"black\">If using BW, must have Runes in Inventory.<br></font>";
		html += "<center><table border=\"0\"><tr><td colspan=\"5\"><center><font size=6><b>== Options and Settings ==</b></font></center></td></tr><tr><td colspan=4><hr></td></tr><tbody><tr><td width=\"135\">";
		html += "<center><td><center><select name=\"where\"><option>F2P or Bounty World<option>P2P or PvP World</select>";
		html += "<tr><td><b>TAB ID:</b></td><td colspan=\"3\"><center><b>Tab ID:</b>&nbsp<input type=\"text\" name=\"TABID\" size=\"4\"></center></td></tr>";
		html += "</center>";
		html += "</center></body>";
		html += "</html>";
		return (html);
	}

	public boolean onStart(final Map<String, String> args) {
		log("Started DPBuilder, GL with getting EP up.");
		WhereToTele = args.get("where");
		if (!args.get("TABID").equals("")) {
			TID = Integer.parseInt(args.get("TABID"));
		}
		return true;
	}

	public boolean Teleport() {

		if (WhereToTele.equals("F2P or Bounty World")) {
			log("Chosen F2P or Bounty World.");
			if (getCurrentTab() != TAB_MAGIC)
				openTab(TAB_MAGIC);
			if (getCurrentTab() == TAB_MAGIC)
				clickMouse(random(665, 675), random(273, 277), true);
			wait(random(1100, 16000));
			stopAllScripts();
			return true;
		}
		if (WhereToTele.equals("P2P or PvP World")) {
			log("Chosen P2P or PvP World.");
			if (getCurrentTab() != TAB_INVENTORY)
				openTab(TAB_INVENTORY);
			if (getCurrentTab() == TAB_INVENTORY)
				atInventoryItem(TID, "Break");
			wait(random(11000, 16000));
			stopAllScripts();
			return true;
		}
		return true;
	}

	public void onFinish() {
		long millis = System.currentTimeMillis() - startTime;
		long hours = millis / (1000 * 60 * 60);
		millis -= hours * (1000 * 60 * 60);
		long minutes = millis / (1000 * 60);
		millis -= minutes * (1000 * 60);
		long seconds = millis / 1000;
		Bot.getEventManager().removeListener(PaintListener.class, this);
		log("Thanks for using the script!");
		log("Runned For : " + hours + "h " + minutes + "min " + seconds
				+ "sec.");
	}

	@Override
	public int loop() {
		if (Teleport()) {
			wait(random(300, 500));
			return random(50, 100);
		}

		return -1;
	}

	// Paint of the script
	public void onRepaint(Graphics g) {
		if (isLoggedIn()) {
			long millis = System.currentTimeMillis() - startTime;
			long hours = millis / (1000 * 60 * 60);
			millis -= hours * (1000 * 60 * 60);
			long minutes = millis / (1000 * 60);
			millis -= minutes * (1000 * 60);
			long seconds = millis / 1000;

			int x = 0;
			int y = 20;

			g.setColor(new Color(0, 100, 0, 100));
			g.setColor(Color.BLUE);
			g.drawString("Mouchicc's Drop Potential Builder", x + 10, y += 15);
			g.setColor(Color.GREEN);
			g.drawString("Running For : " + hours + "h " + minutes + "min "
					+ seconds + "sec.", x + 10, y += 15);
			g.setColor(Color.YELLOW);
			g.drawString("GET THE EP UP!", x + 10, y += 15);
		}
	}
}
